Lecture 28 – Review, Conclusion

DSC 10, Fall 2022

Announcements

Agenda

Bakeries 🧁

Let's pick up where we left off last lecture.

Concept Check ✅ – Answer at cc.dsc10.com

Using a single sample of 200 bakeries, how can we estimate the median inspection score of all bakeries in San Francisco with an inspection score? What technique should we use?

A. Standard hypothesis testing

B. Permutation testing

C. Bootstrapping

D. The Central Limit Theorem

Click for the answer after you've entered your guess above. Don't scroll any further. Bootstrapping. The CLT only applies to sample means (and sums), not to any other statistics.

There is no CLT for sample medians, so instead we'll have to resort to bootstrapping to estimate the distribution of the sample median.

Recall, bootstrapping is the act of sampling from the original sample, with replacement. This is also called resampling.

Let's resample repeatedly.

Note that this distribution is not at all normal.

To compute a 95% confidence interval, we take the middle 95% of the bootstrapped medians.

Discussion Question

Which of the following interpretations of this confidence interval are valid?

  1. 95% of SF bakeries have an inspection score between 85 and 88.
  2. 95% of the resamples have a median inspection score between 85 and 88.
  3. There is a 95% chance that our sample has a median inspection score between 85 and 88.
  4. There is a 95% chance that the median inspection score of all SF bakeries is between 85 and 88.
  5. If we had taken 100 samples from the same population, about 95 of these samples would have a median inspection score between 85 and 88.
  6. If we had taken 100 samples from the same population, about 95 of the confidence intervals created would contain the median inspection score of all SF bakeries.
Click for the answer after you've entered your guess above. Don't scroll any further. The correct answers are Option 2 and Option 6.

Physicians 🩺

The setup

You work as a family physician. You collect data and you find that in 6354 patients, 3115 were children and 3239 were adults.

You want to test the following hypotheses:

Concept Check ✅ – Answer at cc.dsc10.com

Which test statistic(s) could be used for this hypothesis test? Which values of the test statistic point towards the alternative?

A. Proportion of children seen
B. Number of children seen
C. Number of children minus number of adults seen
D. Absolute value of number of children minus number of adults seen

There may be multiple correct answers; choose one.

Click for the answer after you've entered your guess above. Don't scroll any further. All of these but the last one would work for this alternative. Small values of these statistics would favor the alternative. If the alternative was instead "Family physicians see a different number of children and adults", the last option would work while the first three wouldn't.

Let's use option B, the number of children seen, as a test statistic. Small values of this statistic favor the alternative hypothesis.

How do we generate a single value of the test statistic?

As usual, let's simulate the test statistic many, many times.

Recall that you collected data and found that in 6354 patients, 3115 were children and 3239 were adults.

Concept Check ✅ – Answer at cc.dsc10.com

What goes in blank (a)?

p_value = np.count_nonzero(test_stats __(a)__ 3115) / 10000

A. >=

B. >

C. <=

D. <

Click for the answer after you've entered your guess above. Don't scroll any further. <=

Concept Check ✅ – Answer at cc.dsc10.com

What do we do, assuming that we're using a 5% p-value cutoff?

A. Reject the null

B. Fail to reject the null

C. It depends

Click for the answer after you've entered your guess above. Don't scroll any further. Fail to reject the null, since the p-value is above 0.05.

Note that while we used np.random.multinomial to simulate the test statistic, we could have used np.random.choice, too:

Concept Check ✅ – Answer at cc.dsc10.com

Is this an example of bootstrapping?

A. Yes, because we are sampling with replacement.

B. No, this is not bootstrapping.

Click for the answer after you've entered your guess above. Don't scroll any further. No, this is not bootstrapping. Bootstrapping is when we resample from a single sample; here we're simulating data under the assumptions of a model.

Personal projects

Using Jupyter Notebooks after DSC 10

Finding data

These sites allow you to search for datasets (in CSV format) from a variety of different domains. Some may require you to sign up for an account; these are generally reputable sources.

Note that all of these links are also available at rampure.org/find-datasets.

Domain-specific sources of data

Tip: if a site only allows you to download a file as an Excel file, not a CSV file, you can download it, open it in a spreadsheet viewer (Excel, Numbers, Google Sheets), and export it to a CSV.

Join a DS3 Project Group 🤝

The Data Science Student Society’s Projects Committee has opened its applications for the Winter 2023 cohort!

Apply here by Sunday at 11:59pm (ignore the deadline on the form). Contact ds3projects@gmail.com with questions.

Demo: Gapminder 🌎

plotly

Gapminder dataset

Gapminder Foundation is a non-profit venture registered in Stockholm, Sweden, that promotes sustainable global development and achievement of the United Nations Millennium Development Goals by increased use and understanding of statistics and other information about social, economic and environmental development at local, national and global levels. - Gapminder Wikipedia

The dataset contains information for each country for several different years.

Let's start by just looking at 2007 data (the most recent year in the dataset).

Scatter plot

We can plot life expectancy vs. GDP per capita. If you hover over a point, you will see the name of the country.

In future courses, you'll learn about transformations. Here, we'll apply a log transformation to the x-axis to make the plot look a little more linear.

Animated scatter plot

We can take things one step further.

Watch this video if you want to see an even-more-animated version of this plot.

Animated histogram

Choropleth

Parting thoughts

From Lecture 1: What is "data science"?

Data science is about drawing useful conclusions from data using computation. Throughout the quarter, we touched on several aspects of data science:

Note on grades

Suraj's freshman year transcript.

Don't let your grades define you, they don't tell the full story.

Procrastination

Adjusting to life in college can be challenging, particularly because it can be hard to manage your time wisely.

If you're interested, register to attend this workshop on overcoming procrastination taught by another data science professor next quarter – participants each receive a $50 Amazon gift card!

Thank you!

This course would not have been possible without...

Good luck on your finals! 🎉

and see you tomorrow at 11:30am. ⏰